from control.new_control import new_process
from control.setting_control import setting_process
from gui.ui_about import CreateAboutWindow
from gui.ui_new import NewParams, CreateNewWindow
from gui.ui_setting import CreateSettingWindow, SettingParams
from utils.delLayout import delLayout

from var import core, screen, author
from workThread.UIWorker import UIWorker


def new_click(ui_main):
    new_params = NewParams(core.getPidCount(), new_process)
    newWin = CreateNewWindow(screen, new_params, ui_main)
    newWin.show()
    newWin.exec()


def setting_click():
    first = core.getTimeSlice()[0]
    second = core.getTimeSlice()[1]
    third = core.getTimeSlice()[2]
    setting_params = SettingParams(first, second, third, setting_process)
    settingWin = CreateSettingWindow(screen, setting_params)
    settingWin.show()
    settingWin.exec()


def about_click():
    print(author)
    aboutWin = CreateAboutWindow(screen)
    aboutWin.show()
    aboutWin.exec()


def reset_click(ui_main):
    core.reset()
    ui_main.time_show.setText("时间：0")
    ui_main.refreshInit(core.getMission().zero_level_queue.queue)
    delLayout(ui_main.output1)


def run_click(ui_main):
    print("receive run_click")
    global ui_worker
    ui_worker = UIWorker(core.getMission())
    ui_worker.current_time_signal.connect(ui_main.refreshTime)
    ui_worker.init_signal.connect(ui_main.resetInitList)
    ui_worker.first_signal.connect(ui_main.resetFirstList)
    ui_worker.second_signal.connect(ui_main.resetSecondList)
    ui_worker.third_signal.connect(ui_main.resetThirdList)

    ui_worker.output1_signal.connect(ui_main.flushOutput1)
    ui_worker.start()
